package com.test.fileapplication.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;


/**
 * Created by Administrator on 2018/4/16.
 */

public class FullyGridLayoutManager extends GridLayoutManager {
    private BaseQuickAdapter adapter;

    public FullyGridLayoutManager(Context context, int spanCount) {
        super(context, spanCount);
    }

    public FullyGridLayoutManager(Context context, int spanCount, BaseQuickAdapter adapter) {
        super(context, spanCount);
        this.adapter = adapter;
    }

    @Override
    public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
        try {
            super.onLayoutChildren(recycler, state);
        } catch (IndexOutOfBoundsException e) {
            Log.e("problem", "meet a IOOBE in RecyclerView");
        }
    }

    @Override
    public boolean supportsPredictiveItemAnimations() {
        return super.supportsPredictiveItemAnimations();
    }

    @Override
    public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec) {
        try {
            if (adapter != null) {
                int measuredWidth = View.MeasureSpec.getSize(widthSpec);
                int measuredHeight = adapter.getEmptyView().getHeight();
                setMeasuredDimension(measuredWidth, measuredHeight);
            } else {
                super.onMeasure(recycler, state, widthSpec, heightSpec);
            }

        } catch (Exception e) {
            super.onMeasure(recycler, state, widthSpec, heightSpec);
        }

    }

}
